const fs = require("fs");
const path = require("path");
const { Document, Packer, Paragraph, TextRun } = require("docx");
const outputDir =  path.join(__dirname, 'uploads');;
if(!fs.existsSync(outputDir)){
    fs.mkdirSync(outputDir);
}
(async ()=>{
    for(i =0;i < 30;i++){
        const fileName = `word_file_${i}.docx`;
        const filePath = path.join(outputDir, fileName);

            // 创建 Word 文档
        const doc = new Document({
        sections: [
          {
            children: [
              new Paragraph(`这是第 ${i} 个 Word 文件的内容。`),
              new Paragraph('欢迎使用 Node.js 和 docx 库！'),
            ],
          },
        ],
      });
    
        // 文件内容
        const buffer = await Packer.toBuffer(doc);
        fs.writeFileSync(filePath, buffer);
        console.log(`已创建文件: ${fileName}`);
    }
    console.log('所有 Word 文件已成功创建！');
})()
